﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Google.Translates.Core;

namespace ml_test_google_trans.Translate
{
    public partial class GetLanguageInfos : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnGetLangInfos_Click(object sender, EventArgs e)
        {
            var startDate = DateTime.Now;
            var langInfos = new TranslatorByGoogleHttp().GetLanguageInfos(ddlTarget.SelectedValue);
            var sp = DateTime.Now - startDate;
            lblMsg.Text = "Get Language Infos Used [ "+sp.TotalMilliseconds+" ] ms";
            if(langInfos!=null && langInfos.Data != null && langInfos.Data.Languages.Length > 0)
            {
                foreach(var langItem in langInfos.Data.Languages)
                {
                    var tr = new HtmlTableRow();
                    var tdKey = new HtmlTableCell {InnerText = "Language : " + langItem.Language, BgColor=Color.Yellow.Name,Width="25%", BorderColor=Color.Gray.Name};
                    var tdName = new HtmlTableCell { Width = "25%", BgColor = "#99CCFF" , BorderColor=Color.Gray.Name};
                    if (!string.IsNullOrEmpty(langItem.Name))
                        tdName.InnerText = "Name:[" + langItem.Name + "]";
                    tr.Cells.Add(tdKey);
                    tr.Cells.Add(tdName);
                    tblInfos.Rows.Add(tr);
                }
            }
        }
    }
}
